/******************************************************************************************************************
 * File:MiddleFilter.java
 * Course: 17655
 * Project: Assignment 1
 * Copyright: Copyright (c) 2003 Carnegie Mellon University
 * Versions:
 *	1.0 November 2008 - Sample Pipe and Filter code (ajl).
 *
 * Description:
 *
 * This class serves as an example for how to use the FilterRemplate to create a standard filter. This particular
 * example is a simple "pass-through" filter that reads data from the filter's input port and writes data out the
 * filter's output port.
 *
 * Parameters: 		None
 *
 * Internal Methods: None
 *
 ******************************************************************************************************************/
package a1.Sample1;

import java.io.IOException;

import edu.cmu.arch.pipesandfilters.frame.Frame;
import edu.cmu.arch.pipesandfilters.frame.Variable;


public class MiddleFilter extends FrameFilter {
	public void run() {

		// Next we write a message to the terminal to let the world know we are
		// alive...
		System.out.print("\n" + this.getName() + "::Middle Reading ");

		Frame frame = null;
		try {
			while (true) {
				// Test Reading A Frame
				frame = readFrame(); 
				System.out.println(Variable.Time.name() + ": " + frame.getValue(Variable.Time));
				System.out.println(Variable.Velocity.name() + ": " + frame.getValue(Variable.Velocity));
				System.out.println(Variable.Altitude.name() + ": " + frame.getValue(Variable.Altitude));
				System.out.println(Variable.Pressure.name() + ": " + frame.getValue(Variable.Pressure));
				System.out.println(Variable.Temperature.name() + ": " + frame.getValue(Variable.Temperature));
				System.out.println(Variable.Attitude.name() + ": " + frame.getValue(Variable.Attitude));
				System.out.println(Variable.ExtrapolatedId.name() + ": " + frame.getValue(Variable.ExtrapolatedId));
				
				// Test Writing A Frame
				writeFrame(frame); 				
			}
		} catch (IOException ioe) {
			System.out.println("IOException while reading input stream:  " + ioe.getMessage());
		} catch (EndOfStreamException e) {
			System.out.println("End of stream caught");
		} finally {
			ClosePorts();
			System.out.print("\n" + this.getName() + "::Middle Exiting");
		}


	} 

} // MiddleFilter